﻿create PROCEDURE Sync.SP_LoanInstallmentPayments_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanInstallmentPaymentID],
		g.[LoanExecutionInstallmentID],g.[PaymentAmount],g.[PaymentDate],g.[ReceiptID],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanInstallmentPayments] g RIGHT JOIN Sync.LoanInstallmentPayments_Tracking t  
    ON t.LoanInstallmentPaymentID = g.LoanInstallmentPaymentID 
    join LoanExecutionInstallments lei on lei.LoanExecutionInstallmentID = g.LoanExecutionInstallmentID
	join LoanExecution le on le.LoanExecutionID = lei.LoanExecutionID
	join CustomerLoans cl
	on le.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END











